package com.visikard.ui.activity;

import com.visikard.application.VKRegApplication;
import com.visikard.ui.R;
import com.visikard.utility.ScalingUtilities;
import com.visikard.utility.ScalingUtilities.ScalingLogic;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class CouponPreviewActivity extends BaseFragmentActivity{
	private CouponPreviewActivity me=this;
	private ImageView mImageView_coupon;
	private TextView mTextView_name,mTextView_percent,mTextView_expire_date;
	private Button mButton_back,mButton_save;
	private CheckBox mCheckBox_termOfUse;
	private void initControls(){
		
		mImageView_coupon=(ImageView) me.findViewById(R.id.coupon_image);
		mTextView_name=(TextView) me.findViewById(R.id.name);
		mTextView_percent=(TextView) me.findViewById(R.id.percent_off);
		mTextView_expire_date=(TextView) me.findViewById(R.id.expire_date);
		
		mButton_back=(Button) me.findViewById(R.id.btn_back);
		mButton_save=(Button) me.findViewById(R.id.btn_save);
		
		mCheckBox_termOfUse=(CheckBox) me.findViewById(R.id.chk_confirm);
		mCheckBox_termOfUse.setOnCheckedChangeListener(new MyOnCheckChangedListener());
		
		mButton_back.setOnClickListener(new MyOnClickListener());
		mButton_save.setOnClickListener(new MyOnClickListener());
		
		Bitmap bitmap=(Bitmap) VKRegApplication.instance.getData(CouponCameraPreviewActivity.CROPPED_BITMAP);
		
		Bitmap scaledBitmap = ScalingUtilities.createScaledBitmap(
				bitmap, bitmap.getWidth(), bitmap.getHeight(), ScalingLogic.CROP);
		bitmap.recycle();
		
		mImageView_coupon.setImageBitmap(scaledBitmap);
	}
	@Override
	protected void onCreate(Bundle bundle) {
		// TODO Auto-generated method stub
		super.onCreate(bundle);
		setContentView(R.layout.coupon_preview_activity);
		initControls();
	}
	private class MyOnClickListener implements OnClickListener{

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			if(v==mButton_back){
				finish();
			}else if(v==mButton_save){
				Log.e(">>>>", mCheckBox_termOfUse.isChecked()+"");
			}
		}
		
	}
	private class MyOnCheckChangedListener implements OnCheckedChangeListener{

		@Override
		public void onCheckedChanged(CompoundButton buttonView,
				boolean isChecked) {
			// TODO Auto-generated method stub
			if(buttonView.isChecked()){
				buttonView.setChecked(true);
			}else{
				buttonView.setChecked(false);
			}
		}
		
	}
}
